package com.emex.app.stuff.security;

import com.emex.app.stuff.security.ui.LoginDialog;
import java.awt.Desktop;
import javax.swing.SwingUtilities;

/**
 *
 * @author Pavel Sedov
 */
public class LoginHandler {

    private static final LoginHandler instance = new LoginHandler();
    private final LoginDialog loginDialog;

    /**
     * Private constructor.
     */
    private LoginHandler() {
        //TODO: get app version from props
        loginDialog = new LoginDialog("Рабочее место Emex", "1.0");
    }

    /**
     * Get instance of the LoginHandler class. Use this method instead of direct
     * initiation of objects.
     *
     * @return instance of the LoginHandler class
     */
    public static LoginHandler getDefault() {
        return instance;
    }

    /**
     * This method shows Login dialog box and blocks application.
     */
    public void showLoginDialog() {
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                if (Desktop.isDesktopSupported()) {
                    loginDialog.setVisible(true);
                }
            }
        });
    }
}
